﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NPOI.SS.Formula.Functions;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
namespace CoreMembers.FileHelp
{
    public class QuestPDFUtils
    {
        public static string PDF_PATH = $"D:\\QuestPDF.pdf";
        public static void GeneratePDF()
        {
            QuestPDF.Settings.License = LicenseType.Community;
            var rows = new[]
 {
     new { Name = "John", Age = 30 },
     new { Name = "Jane", Age = 25 },
     new { Name = "Tom", Age = 35 }
    };

            // 创建 PDF 文档并进行布局
            var document = Document.Create(container =>
            {
                container.Page(page =>
                {
                    page.Margin(50); // 设置页面边距

                    page.Content().Column(column =>
                    {
                        column.Item().Text("Hello, NetShare!").FontSize(24).Bold(); // 添加文本
                        column.Item().Text("Centered Text")
  .AlignCenter()
  .FontSize(18)
  .FontColor(Colors.Blue.Medium);
                        column.Item().Text("Welcome to follow the official account: Net Sharing");
                        //column.Item().Image("20210517111144223.png"); // 插入图像 

                        column.Item().Text("Dynamic Table").AlignCenter().FontSize(24).Bold();

                        column.Item().Table(table =>
                        {
                            table.ColumnsDefinition(columns =>
                            {
                                columns.ConstantColumn(150);  // 固定宽度
                                columns.RelativeColumn();     // 自动分配剩余空间
                            });

                            table.Header(header =>
                            {
                                header.Cell().Text("Name");
                                header.Cell().Text("Age");
                            });

                            foreach (var row in rows)
                            {
                                table.Cell().Text(row.Name);
                                table.Cell().Text(row.Age.ToString());
                            }
                        });
                    });
                });
            });

            // 保存 PDF 文件
            document.GeneratePdf(PDF_PATH);
        }
    }
}
